<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="UTF-8"/>
    <title>线下订单供应链分润</title>
    <link href="${ctx}/static/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/static/dist/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/static/plugins/datatables/css/matrix-style.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/static/dist/css/AdminLTE.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/static/plugins/datatables/css/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
    <style>
        button.searching{
            background-color:#666
        }
    </style>
</head>
<body>
<div class="widget-box">
	<div class="widget-title">
	   <h5>请输入查询条件</h5>
	</div>
	<div class="widget-content nopadding">
		<table style="line-height:45px;font-size:12px;">
			<tr>
				<td>&nbsp;&nbsp;&nbsp;订单号：</td>
				<td><input type="text" class="form-control" name="orderNo" id="orderNo"  style="width:200px;" placeholder="请输入订单号" ></td>
				<td>&nbsp;&nbsp;&nbsp;订单类型：</td>
				<td>
				<select name="orderType" id="orderType" class="form-control">   
			        <option value="-1" selected="selected">全部</option>    
			        <option value="1">分润</option>   
			        <option value="2">商户提现</option> 
			        <option value="3">代理提现</option>   
			      </select>
				</td>
				<td>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-success" href="javacript:void(0);" onclick="query();">查 询</a>
				</td>
				<td>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-primary" href="/api/unLineOrderProfit/exportUnlineOrderSupplyChainProfit" id="exportExcel">导出数据</a>
				</td>		
			</tr>
		</table>
	 	<div id="area_div" style="margin-left: 10px"></div>
	</div>
</div>
 <div class="row">
		 <div class="col-xs-12">
		 	<div class="box">
		 		<div class="box-header">
	                 <h3 class="box-title">线下订单供应链利润分成表</h3>
	             </div>
	             <!-- 列表 -->
	             <div class="box-body table-responsive">
	             	<table id="dataTables" class="table table-bordered table-hover">
	             	</table>
	             </div>
		 	</div>
		 </div>
	</div>
<script src="${ctx}/static/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="${ctx}/static/bootstrap/js/bootstrap.min.js"></script>
<!-- datatable -->
<script src="${ctx}/static/plugins/datatables/jquery.dataTables.js" type="text/javascript"></script>
<script src="${ctx}/static/plugins/datatables/dataTables.bootstrap.js" type="text/javascript"></script>
<script src="${ctx}/static/js/common/area.js" type="text/javascript"></script>
<script>
   var tb;
   $(function () {
		//列表初始化
		tb = $('#dataTables').dataTable({
				"bServerSide": true,
				"sPaginationType": "full_numbers",
				"bJQueryUI": true,
				"sDom": '<"">t<"F"ip>',
				"sAjaxSource": "${ctx}/api/unLineOrderProfit/unLineOrderSupplyChainList", //ajax调用接口
				"aoColumnDefs": [{sDefaultContent: '',aTargets: [ '_all' ]}],
	       		"aoColumns": [
		                { "sTitle" : "序号","mData": "id","class":"sClass" },
		                { "sTitle" : "订单号","mData": "orderNo","class":"sClass" },
		                { "sTitle" : "零售价","mData": "price","class":"sClass" },
		                { "sTitle" : "结算成本","mData": "cost","class":"sClass" },
		                { "sTitle" : "门店进货价格","mData": "buyExpense","class":"sClass" },
		                { "sTitle" : "物流费用","mData": "logisticsFee","class":"sClass" },
		                { "sTitle" : "供应链利润","mData": "chainProfit","class":"sClass" },
		                { "sTitle" : "普惠供应链收入","mData": "phIncome","class":"sClass" },
		                { "sTitle" : "易商通供应链收入","mData": "ystIncome","class":"sClass" },
		                { "sTitle" : "市代名称","mData": "shiName","class":"sClass" },
		                { "sTitle" : "市级代理分润","mData": "cityProfit","class":"sClass" },
		                { "sTitle" : "县代名称","mData": "xianName","class":"sClass" },
		                { "sTitle" : "县级代理分润","mData": "countyProfit","class":"sClass" },
		                { "sTitle" : "社区代名称","mData": "quName","class":"sClass" },
		                { "sTitle" : "社区代理分润","mData": "communityProfit","class":"sClass" },
		                { "sTitle" : "供应链支出合计","mData": "chainTotal","class":"sClass" },
		                { "sTitle" : "供应链剩余","mData": "chainRemain","class":"sClass" },
		                { "sTitle" : "易商通总余","mData": "ystRemain","class":"sClass" },
		                { "sTitle" : "普惠总余","mData": "phRemain","class":"sClass" },
		                { "sTitle" : "买家名称","mData": "buyerName","class":"sClass" },
		                { "sTitle" : "卖家名称","mData": "sellerName","class":"sClass" },   
		                { "sTitle" : "提现人名称","mData": "withdrawalsName","class":"sClass" }, 
		                {
		                    "sTitle": "订单类型 ", "mData": "orderType", "class": "sClass", "mRender": function (data, type, full) {
		                    var text;
		                    if (full.orderType == '1') {
		                        text = "<font color='blue'>分润</font>";
		                    } else if (full.orderType == '2') {
		                        text = "<font color='green'>商户提现</font>"
		                    }else if (full.orderType == '3') {
		                        text = "<font color='green'>代理提现</font>"
		                    }
		                    return text;
		                }
		                },
		                {
		                    "sTitle": "状态", "mData": "examineType", "class": "sClass", "mRender": function (data, type, full) {
		                    var text;
		                    if (full.examineType == '1') {
		                        text = "<font color='blue'>待审核</font>";
		                    } else if (full.examineType == '2') {
		                        text = "<font color='green'>通过</font>"
		                    } else if (full.examineType == '3') {
		                        text = "<font color='blue'>未通过</font>"
		                    }
		                    return text;
		                }
		                },
		                {"sTitle" : "操作","mData" : "id", "mRender" : function ( data, type, full ) {
		                	  var text = '<div class="btn-group" style="text-align:left;"><button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown">操作 <span class="caret"></span></button>';
								  if(full.examineType == '1' && full.orderType =='1'){
									 	text = text+'<ul class="dropdown-menu" role="menu">';
				                    	text += '<li><a href="#" onclick="pass(\'' + full.id + '\',\''+full.merchantTel+'\');">通过</a> </li>';
				                        text += '<li class="divider"></li>';
				                        text += '<li><a href="#" onclick="noPass(\'' + full.id + '\');">不通过</a> </li>';
				                        text = text + '</ul></div>';
				                    }
								    if((full.orderType == '2' || full.orderType == '3' ) && full.examineType == '1'){  
								    	text = text+'<ul class="dropdown-menu" role="menu">';
				                    	text += '<li><a href="#" onclick="withdrawals(\'' + full.id + '\',\''+full.orderType+'\',\''+full.price+'\',\''+full.withdrawalsId+'\',\''+full.orderNo+'\');">通过</a> </li>';
				                    	text += '<li class="divider"></li>';
				                        text += '<li><a href="#" onclick="noPassWithdrawals(\'' + full.id + '\',\''+full.orderType+'\',\''+full.price+'\',\''+full.withdrawalsId+'\',\''+full.orderNo+'\');">不通过</a> </li>';
				                        text = text+'<ul class="dropdown-menu" role="menu">';
								    }
								  return text;
								} 
			           }
	            ],
		        "oLanguage" : {
		           "sProcessing" : "数据加载中······",
		           "sLengthMenu" : "显示 _MENU_ 条记录",
		           "sZeroRecords" : "没有您要搜索的内容！",
		           "sEmptyTable" : "列表中无数据存在！",
		           "sInfo" : "当前显示 _START_ 到 _END_ 条数据，共 _TOTAL_ 条数据",
		           "sInfoEmpty" : "显示 0 到 0 条记录",
		           "sInfoFiltered" : "数据列表中共  _MAX_ 条记录",
		           "oPaginate" : {
		               "sFirst" : "首页",
		               "sPrevious" : "上一页",
		               "sNext" : "下一页",
		               "sLast" : "末页"
		           }
		        },
		        "fnServerData" : function ( sSource, aoData, fnCallback, oSettings ) {
					oSettings.jqXHR = $.ajax( {
						"dataType" 	: 'json',
						"type" 		: "GET",
						"async"     : 'false',
						"url" 		: sSource,
						"data" 		: {
							'pageNum': (aoData[3].value/aoData[4].value)+1,
							'pageSize' :  aoData[4].value,
							'orderNo'  :  $("#orderNo").val(),
							'orderType' : $("select[name='orderType']").val(),
						}, 
						"success"	: fnCallback
					} );
				},
		  });
   });
   //条件查询重新加载数据
   function query() {
	   tb.fnDraw();
   }   
   
 //通过
   function pass(id,merchantTel) {
       if (confirm("确认通过?") == true) {
           $.ajax({
               async: false,
               url: "/api/unLineOrderProfit/updateProfitStatues",
               data: {id: id, examineType: 2},
               type: "POST",
               dataType: "json",
               success: function (data) {
                   if (data.code = "200") {
                       tb.fnDraw();
                   } else {
                       alert(data.message);
                   }
               }
           });

       } else {
           return false;
       }
   }

   //不通过 更改状态
   function noPass(id) {
       if (confirm("确认不通过？") == true) {
           $.ajax({
               async: false,
               url: "/api/unLineOrderProfit/updateProfitStatues",
               data: {id: id, examineType: 3},
               type: "POST",
               dataType: "json",
               success: function (data) {
                   if (data.code = "200") {
                       tb.fnDraw();
                   } else {
                       alert(data.message);
                   }
               }
           });

       } else {
           return false;
       }
   }
   
 //提现
   function withdrawals(id,orderType,price,withdrawalsId,orderNo) {
       if (confirm("确认提现？") == true) {
           $.ajax({
               async: false,
               url: "/api/merchant/userWithdrawals",
               data: {id: id, orderType: orderType,price:price,withdrawalsId : withdrawalsId,orderNo:orderNo,type : 1},
               type: "POST",
               dataType: "json",
               success: function (data) {
                   if (data.code = "200") {
                	   alert(data.message);
                       tb.fnDraw();
                   } else {
                       alert(data.message);
                   }
               }
           });

       } else {
           return false;
       }
   }
   //提现 直接审核不通过
   function noPassWithdrawals(id,orderType,price,withdrawalsId,orderNo) {
       if (confirm("确认审核不通过吗？") == true) {
           $.ajax({
               async: false,
               url: "/api/merchant/userWithdrawals",
               data: {id: id, orderType: orderType,price:price,withdrawalsId : withdrawalsId,orderNo:orderNo,type : 2},
               type: "POST",
               dataType: "json",
               success: function (data) {
                   if (data.code = "200") {
                	   alert(data.message);
                       tb.fnDraw();
                   } else {
                       alert(data.message);
                   }
               }
           });

       } else {
           return false;
       }
   }
</script>
</body>
</html>